package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 模板状态枚举
 * 
 * @author S-01 Module Designer
 * @version 2.0
 * @since 2025-11-10
 */
public enum TemplateStatus implements BaseEnum {
    DRAFT("draft", "草稿"),
    ACTIVE("active", "激活"),
    INACTIVE("inactive", "未激活"),
    ARCHIVED("archived", "已归档"),
    PUBLISHED("published", "已发布"),
    DEPRECATED("deprecated", "已弃用"),
    UNDER_REVIEW("under_review", "审核中"),
    APPROVED("approved", "已批准"),
    REJECTED("rejected", "已拒绝");

    private final String code;
    private final String description;

    TemplateStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    public String getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据代码查找枚举值
     *
     * @param code 枚举代码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果代码不存在
     */
    public static TemplateStatus fromCode(String code) {
        for (TemplateStatus status : TemplateStatus.values()) {
            if (status.code.equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown template status code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 枚举描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述不存在
     */
    public static TemplateStatus fromDescription(String description) {
        for (TemplateStatus status : TemplateStatus.values()) {
            if (status.description.equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown template status description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}